package spring;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
import standalone.AbsResourceHandler;

;import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * UUID静态资源处理,spring mvc4.3 以后注入resource下载处理器
 *
 * @see ResourceHttpRequestHandler#handleRequest(HttpServletRequest, HttpServletResponse)
 * author:xiaobo
 * date: 2016/10/12.
 */
public class UUIDResourcesHandler extends ResourceHttpRequestHandler {
    private static final Logger logger = LoggerFactory.getLogger(UUIDResourcesHandler.class);


    @PostConstruct
    protected void init(){
        WebPointLoad.resourcesHandler =this;
    }


    @Override
    protected MediaType getMediaType(Resource resource) {
        UUIDFileResource uuidFileResource =null;
        if(resource instanceof UUIDFileResource){
            uuidFileResource = (UUIDFileResource)resource;
            return  MediaType.parseMediaType(uuidFileResource.getMimeType());
        }
        return null;
    }

}
